function HandlePageIeCustomerWed(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  this._queue = 0;
  
  this._createElements();
};

HandlePageIeCustomerWed.prototype._createElements = function() {
  var _self = this;
  this._popupBox = new PopupBox();
  this._search = DlmanageUtils.search();
  
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.backgroundColor = '#fff';
  td.colSpan = 17;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePageIeCustomerWed.prototype._loadData = function() {
  this._results = null;
  this._customers = null;
  this._parameters = null;
  this._retrieveResults(1);
  this._retrieveCustomers(1);
};

HandlePageIeCustomerWed.prototype._verifyData = function() {
  if (this._results && this._customers && this._results && this._parameters) {
    this._updateElements();
  }
};

HandlePageIeCustomerWed.prototype._retrieveResults = function(page, order, queue, condition, from, to) {
  var _self = this;
  var args = 'ot={{$smarty.const.ORDER_TYPE_WEDDING|escape:'javascript'}}&c=LEFT JOIN ns__ez_relation_customer_myorder AS co ON co.oid_a = c.e_oid LEFT JOIN ' + DlmanageUtils.tableMyOrder + ' AS o ON o.e_oid = co.oid_b LEFT JOIN ns__ez_relation_myorder_myordercancel AS od ON o.e_oid = od.oid_a LEFT JOIN ' + DlmanageUtils.tableMyOrderCancel + ' AS d ON d.e_oid = od.oid_b WHERE d.status = 0 AND o.type = \'{{$smarty.const.ORDER_TYPE_WEDDING|escape:'javascript'}}\' AND ' + ((condition) ? condition : '1 = 1') + ((from) ?  '&from=' + from : '') + ((to) ?  '&to=' + to : '');
  new RequestUtils()._mysql('ieincomecustomer', args, function(result, params) { _self._results = result;
                                                                                 _self._verifyData.call(_self);
                                                                               }, null);
};

HandlePageIeCustomerWed.prototype._retrieveCustomers = function(page, order, queue, condition, from, to) {
  var _self = this;
  if (condition) {
    var tmp = condition.indexOf('WHERE');
    condition = condition.substr((tmp != -1) ? tmp + 6 : 0);
  }
  var args = 'c=LEFT JOIN ns__ez_relation_customer_myorder AS co ON co.oid_a = c.e_oid LEFT JOIN ' + DlmanageUtils.tableMyOrder + ' AS o ON o.e_oid = co.oid_b LEFT JOIN ns__ez_relation_myorder_myordercancel AS od ON o.e_oid = od.oid_a LEFT JOIN ' + DlmanageUtils.tableMyOrderCancel + ' AS d ON d.e_oid = od.oid_b WHERE d.status = 0 AND o.type = \'{{$smarty.const.ORDER_TYPE_WEDDING|escape:'javascript'}}\' AND ' + ((condition) ? condition : '1 = 1') + '&s=20' + ((page) ? '&p=' + page : '') + ((order) ? '&o=' + order : '') + ((queue) ? '&q=' + queue : '') + ((from) ?  '&from=' + from : '') + ((to) ?  '&to=' + to : '');
  new RequestUtils()._mysql('customers', args, function(result, params) { _self._customers = result.data;
                                                                              _self._parameters = result;
                                                                              _self._verifyData.call(_self);
                                                                            }, null);
};

HandlePageIeCustomerWed.prototype._updateElements = function() {
  var _self = this;
  DlmanageUtils.clear(this._gui.summarize);
  DOMUtils.removeTableRows(this._gui.mains, 1);
  DOMUtils.removeChildElements(this._gui.pagination);
  
  this._gui.summarize.cNo.appendChild(document.createTextNode(this._results.wed.customer));
  this._gui.summarize.revenue.appendChild(document.createTextNode('$' + parseFloat(this._results.wed.revenue, 10).toFixed(2)));
  this._gui.summarize.receipt.appendChild(document.createTextNode('$' + parseFloat(this._results.wed.receipt, 10).toFixed(2)));
  this._gui.summarize.anticipated.appendChild(document.createTextNode('$' + parseFloat(this._results.wed.anticipated, 10).toFixed(2)));
  this._gui.summarize.cash.appendChild(document.createTextNode('$' + parseFloat(this._results.wed.cash).toFixed(2), 10));
  this._gui.summarize.nonCash.appendChild(document.createTextNode('$' + parseFloat(this._results.wed.noncash, 10).toFixed(2)));
  
  /*-----SORT-----*/
  this._queue = !this._queue;
  this._gui.date.onclick = function() { _self._retrieveCustomers.call(_self, _self._parameters.page, 'c.createdDate', (_self._queue) ? 'ASC' : 'DESC', _self._parameters.condition); };
  this._gui.customer.onclick = function() { _self._retrieveCustomers.call(_self, _self._parameters.page, 'c.e_oid', (_self._queue) ? 'ASC' : 'DESC', _self._parameters.condition); };

  if (this._customers.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.colSpan = 17;
    td.style.height = '24px';
    td.appendChild(document.createTextNode('N/A'));
  }
  for (var i = 0, il = this._customers.length; i < il; i++) {
    var customer = this._customers[i];
    for (var j = 0, jl = customer.orders.length; j < jl; j++) {
      var order = customer.orders[j];
      if (order.disposal.status) {
        continue;
      }
      if (order.type == '{{$smarty.const.ORDER_TYPE_WEDDING|escape:'javascript'}}') {
        tr = this._gui.mains.insertRow(-1);
        td = tr.insertCell(-1);
        td.style.height = '24px';
        td.appendChild(document.createTextNode(SimpleDate.formatEvent(customer.createdDate)));
        td = tr.insertCell(-1);
        td.appendChild(document.createTextNode(DlmanageUtils.customerId(customer.id)));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td13';
        td.appendChild(document.createTextNode((DlmanageUtils.stage(order).pay1.date[0]) ? SimpleDate.formatEvent(DlmanageUtils.stage(order).pay1.date[0]) : ''));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td14';
        td.appendChild(document.createTextNode('$' + (DlmanageUtils.stage(order).pay1.cash).toFixed(2)));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td15';
        td.appendChild(document.createTextNode('$' + (DlmanageUtils.stage(order).pay1.nonCash).toFixed(2)));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td19';
        td.appendChild(document.createTextNode((DlmanageUtils.stage(order).pay2.date[0]) ? SimpleDate.formatEvent(DlmanageUtils.stage(order).pay2.date[0]) : ''));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td20';
        td.appendChild(document.createTextNode('$' + (DlmanageUtils.stage(order).pay2.cash).toFixed(2)));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td21';
        td.appendChild(document.createTextNode('$' + (DlmanageUtils.stage(order).pay2.nonCash).toFixed(2)));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td22';
        td.appendChild(document.createTextNode((DlmanageUtils.stage(order).pay3.date[0]) ? SimpleDate.formatEvent(DlmanageUtils.stage(order).pay3.date[0]) : ''));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td23';
        td.appendChild(document.createTextNode('$' + (DlmanageUtils.stage(order).pay3.cash).toFixed(2)));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td24';
        td.appendChild(document.createTextNode('$' + (DlmanageUtils.stage(order).pay3.nonCash).toFixed(2)));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td25';
        td.appendChild(document.createTextNode((DlmanageUtils.stage(order).pay4.date[0]) ? SimpleDate.formatEvent(DlmanageUtils.stage(order).pay4.date[0]) : ''));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td26';
        td.appendChild(document.createTextNode('$' + (DlmanageUtils.stage(order).pay4.cash).toFixed(2)));
        td = tr.insertCell(-1);
        td.className = 'elemsumcustomerother_td27';
        td.appendChild(document.createTextNode('$' + (DlmanageUtils.stage(order).pay4.nonCash).toFixed(2)));
        td = tr.insertCell(-1);
        td.appendChild(document.createTextNode('$' + order.price));
        td = tr.insertCell(-1);
        td.appendChild(document.createTextNode('$' + (DlmanageUtils.stage(order).receipt).toFixed(2)));
        td = tr.insertCell(-1);
        td.appendChild(document.createTextNode('$' + (order.price - (DlmanageUtils.stage(order).receipt)).toFixed(2)));
      }
    }
  }
  /*--PAGINATION--*/
  Pagination.makePagedResults(this._gui.pagination, this._parameters.page, this._parameters.total, this._parameters.size, function(page, condition) { _self._retrieveCustomers.call(_self, page, _self._parameters.order, _self._parameters.queue, _self._parameters.condition); }, this, document);
  /*---Search--*/
  this._customerSearch(this._gui, function(order, queue, condition, from, to) { _self._retrieveResults.call(_self, 1, order, queue, condition, from, to); _self._retrieveCustomers.call(_self, 1, order, queue, condition, from, to);});
};

HandlePageIeCustomerWed.prototype._customerSearch = function(gui, callbackFunc) {
  var _self = this;
  this._callbackFunc = callbackFunc;
  
  this._search.id = gui.search.cNo.value;
  gui.search.cNo.value = this._search.id;
  gui.search.cNo.onchange = function() { _self._search.id = this.value; };
  gui.search.cNo.onkeydown = function() { _self._search.id = this.value; };
  gui.search.cNo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                            if (code == 13) {
                                              _self._callbackFunc.call(_self, null, null, _self._toString(_self._search), (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null);
                                            }
                                          };
  gui.search.cNo.onkeyup = function() { if (gui.search.cNo.value.length == 0) {
                                          _self._popupBox._close();
                                        } else {
                                          var div = document.createElement('div');
                                          var pos1 = DOMUtils.findPos(gui.search.cNo);
                                          var pos = [pos1[0] + 1, pos1[1] + 82];
                                          var query = "SELECT c.e_oid as id FROM ns_Customer as c WHERE 1 = 1 AND " + '((c.e_oid LIKE \'%' + gui.search.cNo.value + '%\'))' + " ";
                                          MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                          new DialogSearchResult(div, gui.search.cNo, { query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._updateElements();}, width: 150});
                                        }
                                      };
  gui.search.dateCreated.value = (this._search.dateFrom) ? SimpleDate.format(this._search.dateFrom) : '';
  gui.search.dateCreated.onclick = function() { var context = this;
                                                _self._changeDate.call(_self, this, _self._search.dateFrom, function(sd) { _self._search.dateFrom = sd; context.focus(); }, false);
                                                return false;
                                              };
  gui.search.dateCreated.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                    if (code == 13) {
                                                      _self._callbackFunc.call(_self, null, null, _self._toString(_self._search), (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null);
                                                    }
                                                  };
  gui.search.dateTo.value = (this._search.dateTo) ? SimpleDate.format(this._search.dateTo) : '';
  gui.search.dateTo.onclick = function() { var context = this;
                                           _self._changeDate.call(_self, this, _self._search.dateTo, function(sd) { _self._search.dateTo = sd; context.focus(); }, false);
                                           return false;
                                         };
  gui.search.dateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                               if (code == 13) {
                                                 _self._callbackFunc.call(_self, null, null, _self._toString(_self._search), (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null);
                                               }
                                             };
  gui.search.search.onclick = function() { _self._callbackFunc.call(_self, null, null, _self._toString(_self._search), (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null); };
};

HandlePageIeCustomerWed.prototype._toString = function(search) {
  var str = '';
  str += (search.id == '') ? '1 = 1' : ((isNaN(search.id)) ? '1 = 0' : '(c.e_oid = \'' + search.id + '\')');
  return escape(str);
};

HandlePageIeCustomerWed.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandlePageIeCustomerWed.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandlePageIeCustomerWed.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};